import {
  roleList
} from '@/api/role'
export default {
  namespaced: true,
  state() {
    return {
      // 从缓存数据中获取
      roleList: JSON.parse(sessionStorage.getItem('role') || '[]')
    }
  },
  getters: {},
  mutations: {
    getRoleList(state, data) {
      state.roleList = data
    }
  },
  actions: {
    async getRoleListSync(context) {
      const {
        meta,
        data
      } = await roleList()
      if (meta.status === 200) {
        // 触发同步修改数据
        context.commit('getRoleList', data)
      }
    }
  }
}
